package com.shisan.tingshu.order.service.impl;

import com.shisan.tingshu.model.order.LocalMsg;
import com.shisan.tingshu.order.mapper.LocalMsgMapper;
import com.shisan.tingshu.order.mapper.OrderInfoMapper;
import com.shisan.tingshu.order.service.MqOpsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class MqOpsServiceImpl implements MqOpsService {

    @Autowired
    private LocalMsgMapper localMsgMapper;

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    /**
     * 修改本地消息表的状态
     *
     * @param content
     */
    @Override
    public void updateLocalMsgStatus(String content) {

        LambdaQueryWrapper<LocalMsg> wrapper = new LambdaQueryWrapper<LocalMsg>();
        wrapper.eq(LocalMsg::getMsgContent, content);
        LocalMsg localMsg = localMsgMapper.selectOne(wrapper);
        if (localMsg != null) {
            localMsg.setStatus(1);
            localMsgMapper.updateById(localMsg);
        }
    }

    /**
     * 关闭订单
     * @param orderNo
     */
    @Override
    public void cancelOrder(String orderNo) {

        int count = orderInfoMapper.cancelOrder(orderNo);
        log.info("关闭订单：{}", count > 0 ? "成功" : "失败");
    }
}
